grammar Decluse;

options {
    k=1;                                // LL(1) - do not use LL(*)
    language=Java;                      // target language is Java (= default)
    output=AST;                         // build an AST
}

tokens {
    LPAREN      =   '('     ;
    RPAREN      =   ')'     ;

    // keywords
    DECLARATION =   'D:'      ;
    USE         =   'U:'      ;
    PROGRAM     =   'program' ;
}

@lexer::header {
package vb.week4.decluse;
}

@header {
package vb.week4.decluse;
}

program
    :   decluse EOF
            ->  ^(PROGRAM decluse)
    ;

decluse
    :   LPAREN! serie RPAREN!
    ;

serie
    :   (unit)*
    ;
    
unit
    :   DECLARATION^ ID
    |   USE^ ID
    |   LPAREN! serie RPAREN!
    ;

ID
    :   LETTER+
    ;
    
WS
    :   (' ' | '\t' | '\f' | '\r' | '\n')+
            { $channel=HIDDEN; }
    ;

fragment DIGIT  :   ('0'..'9') ;
fragment LOWER  :   ('a'..'z') ;
fragment UPPER  :   ('A'..'Z') ;
fragment LETTER :   LOWER | UPPER ;

// EOF

